package net.viralpatel.struts2;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ChangeWaitUserAction extends ActionSupport {
	private String username;
	private String oldusername;

	private String name;
	private String email;
	private String telephone;
	private String company;
	String url = "jdbc:mysql://localhost:3306/";
	String dbName = "t10";
	String driverName = "com.mysql.jdbc.Driver";
	Connection con = null;

	String nameroot = "root";
	String passwordroot = "";

	public String execute() throws Exception {
		Map session = ActionContext.getContext().getSession();
		try {
			Class.forName(driverName);
			con = DriverManager.getConnection(url + dbName, nameroot,
					passwordroot);
		} catch (ClassNotFoundException e) {
			System.out.println(e.getMessage());
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}

		String selectChangePasswd = "Update user set userID =?,fullname = ?,mail=?," +
				"tel=?,company=? where userID =?";
		PreparedStatement prepStmt = con.prepareStatement(selectChangePasswd);
		prepStmt.setString(1, this.username);
		prepStmt.setString(2, this.name);
		prepStmt.setString(3, this.email);
		prepStmt.setString(4, this.telephone);
		prepStmt.setString(5, this.company);
		prepStmt.setString(6, this.oldusername);
		try {
			int row = prepStmt.executeUpdate();
			if (row != 0) {
				return SUCCESS;
			} else {
				addActionError(getText("error.changewaituser"));
				return ERROR;
			}
		} catch (Exception e) {
			// TODO: handle exception
			addActionError(getText("error.changewaituser"));
			return ERROR;
		}
		
	}


	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getEmail() {
		return email;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	public String getTelephone() {
		return telephone;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getCompany() {
		return company;
	}

	public void setUsername(String username) {
		this.username = username;
	}


	public String getUsername() {
		return username;
	}


	public void setOldusername(String oldusername) {
		this.oldusername = oldusername;
	}


	public String getOldusername() {
		return oldusername;
	}

}
